<?php
/**
 * @name /www/EditNeededItem.php
 * @author
 * @version 2011.04.5
 *
 * This is the page for Editing Orphanage Information by the Administrator.
 */

// Sets up configuration settings and includes libraries.
require_once('_ini.php');

// Libraries
ReqLib('/lib/private/NeededItem.php');
require_once('calendar/classes/tc_calendar.php');

function DefineHeader() {
?>

<script language="javascript" src="calendar/calendar.js"></script>

<?
}

/**
 * Defines page content.
 *
 */
function DefineContent() {
  // Page content goes here.
  ?>
<p>
  <a href="<?=_webroot('/') ?>">Home</a>.
</p>
<?
	if($_SESSION['userId'] >0){
?>
		<p>
		  <a href="<?=_webroot('/account.php') ?>">My Account</a>.
		</p>
		<p>
		  <a href="<?=_webroot('/logout.php') ?>">Logout</a>.
		</p>
    <form  action = "neededItemRequestHandle.php" method="POST">
<center><table border="2">
	<tbody>
<?
	$ni = new NeededItem();
	$neededItemId = $_REQUEST['niId'];

	//print($userId);

	$ni->Load($neededItemId);

	//print_r($u);
	//die();

	if($ni->QuantitySent==NULL)
		$quantitySent=0;
	else
		$quantitySent=$ni->QuantitySent;

	print('<tr><td>Needed Item ID</td><td><input type=text name=NeededItemId value="'.$ni->NeededItemId.'" /></td></tr>');
	?>

	<tr><td>Item Name</td>
	<td>
		<select name="ItemName">
		<?
			foreach(Item::GetItems() as $i)
			{
				if($i->Name == $ni->ItemObject->Name)
					print('<option selected>'.$i->Name.'</option>');
				else
					print('<option>'.$i->Name.'</option>');
			}
		?>
		</select>
	</td>
	</tr>

	<tr><td>Orphanage Name</td>
	<td>
		<select name="OrphanageName">
		<?
			foreach(Orphanage::GetOrphanages() as $o)
			{
				if($o->Name == $ni->OrphanageObject->Name)
					print('<option selected>'.$o->Name.'</option>');
				else
					print('<option>'.$o->Name.'</option>');
			}
		?>
		</select>
	</td>
	</tr>

	<?
	print('<tr><td>Quantity Needed</td><td><input type=text name=NeededQuantity value="'.$ni->NeededQuantity.'" /></td></tr>');
	print('<tr><td>QuantitySent</td><td><input type=text name=QuantitySent value="'.$quantitySent.'" /></td></tr>');
	print('<tr><td>Date Requested</td><td>');

	$myCalendar = new tc_calendar("DateRequested", true, false);
	$myCalendar->setIcon("calendar/images/iconCalendar.gif");
	$myDate = explode("-",$ni->DateRequested);
	$myCalendar->setDate($myDate[2], $myDate[1], $myDate[0]);
	$myCalendar->setPath("calendar/");
	$myCalendar->setYearInterval(2000, 2015);
	$myCalendar->dateAllow('1950-05-13', '2015-03-01');
	$myCalendar->setDateFormat('j F Y');
	$myCalendar->setAlignment('left', 'bottom');
	$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
	$myCalendar->writeScript();

	print('</td></tr>');
	print('<tr><td>Notes</td><td><input type=text name=NeededNotes value="'.$ni->NeededNotes.'" /></td></tr>');
	print('</tbody></table>');
  	print('<input type="submit" name="Action" value="Update Needed Item Info" />');
  	print('<input type="submit" name="Action" value="Delete Needed Item" />');
	print('<input type=button value="Back" onClick="history.go(-1)" />');
	print('</center>');

  	print('</form>');
	}
   else{
?>
		<p>
		  <a href="<?=_webroot('/login_register.php') ?>">Login/Register</a>.
		</p>
<?
   }
}

// Launches the page; without this, nothing happens.
require_once('_loader.php');